package com.jy.wms.common.base;

import com.joyi.gate.comm.SessionInfo;
import com.joyi.gate.safety.vo.UserInfo;
import com.jy.wms.common.SpringUtil;
import com.jy.wms.dao.WmsPackingMapper;
import com.jy.wms.pojo.SysHz;
import org.jeecgframework.poi.handler.impl.ExcelDataHandlerDefaultImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.List;
import java.util.Map;

/**
 * Created by syh on 2018/4/12.
 */
public class WmsPackingMxMapImportHanlder extends ExcelDataHandlerDefaultImpl {
    WmsPackingMapper wmsPackingMapper = SpringUtil.getBean(WmsPackingMapper.class);
    private static Logger log = LoggerFactory.getLogger(WmsPackingMapper.class);
    @Override
    public void setMapValue(Map<String, Object> map, String originKey, Object value) {
        System.out.print("value:" + value);
        log.info("value:" + value);
        /*if (value instanceof Double) {
            NumberFormat nf = new DecimalFormat("#");
            value = nf.format(value);
        }*/
        if(originKey!="" && originKey!=null){
            map.put(getRealKey(originKey), value != null ? value.toString() : null);
        }



    }

    private String getRealKey(String originKey) {
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        HttpSession session = request.getSession();
        UserInfo userinfo = (UserInfo) session.getAttribute(SessionInfo.USER_INFO);//用户信息
        String ckid = String.valueOf(userinfo.getUser().getOrgId().get(0));//仓库id
        List<SysHz> hz = (List) session.getAttribute(BaseSessionInfo.SessionConsignor);
        String hzid = null;
        if (hz.size() > 0) {
            hzid = hz.get(0).getHzid();
        }

        System.out.println("originKey:" + originKey);
        log.info("originKey:" + originKey);
        if (originKey.equals("包装名称")) {
            return "bzmc";
        }
        if (originKey.equals("主包装描述")) {
            return "zbzms";
        }
        if (originKey.equals("包装类型")) {
            return "bzlx";
        }
        if (originKey.equals("数量")) {
            return "sl";
        }
        if (originKey.equals("明细包装描述")) {
            return "mxbzms";
        }
        if (originKey.equals("长(厘米)")) {
            return "clm";
        }
        if (originKey.equals("宽(厘米)")) {
            return "klm";
        }
        if (originKey.equals("高(厘米)")) {
            return "glm";
        }
        if (originKey.equals("体积")) {
            return "tj";
        }
        if (originKey.equals("毛重量(克)")) {
            return "mzlk";
        }
        if (originKey.equals("净重")) {
            return "jz";
        }
        if (originKey.equals("金额")) {
            return "je";
        }
        if (originKey.equals("TI*HI")) {
            return "th";
        }
        return "";
    }

}